<?php
/**
 * Created by PhpStorm.
 * User: Cailusen
 * Date: 2018/3/6
 * Time: 11:24
 */

use Biz\service\Goods;
use Biz\service\GoodsHistory;
use Biz\service\trade\UserAddress;
use Doraemon\service\ABTest\ABFactory as sABFactory;
use Biz\model\GoodsBasicInfo as mGoodsBasicInfo;
use Biz\pockets\constInterface\ActivityInfo;
use Doraemon\model\Member as dbUser;

/**
 * @deprecated
 */
class InfoAction extends ActionPlugin
{

    const USER_LEVEL = self::LEVEL_NOTHING;
    const VIDEO_PYAY = 'a';
    const VIDEO_NOT_PLAY = 'b';

    public function main()
    {
        $uid = $this->uid;
        $goodsId = $this->getRequest()->getQuery('goods_id', 0);
        $provinceId = $this->getRequest()->getQuery('province_id', 0);
        $cityId = $this->getRequest()->getQuery('city_id', 0);
        $activityType = $this->getRequest()->getQuery("activity_type", 0);
        $userCityId = UserAddress::getUserDefaultCityCode($uid);
        $areaCode = $userCityId ? $userCityId : ($cityId ? $cityId : $provinceId);
        $parameter = ['area_code' => $areaCode, 'activity_type' => ActivityInfo::ACTIVITY_TYPE_NORMAL, 'redundancy_type' => ActivityInfo::ACTIVITY_TYPE_PINTUAN, 'not_activity_type' => [ActivityInfo::ACTIVITY_TYPE_PINTUAN]];
        if ($activityType) {
            unset($parameter['redundancy_type'], $parameter['not_activity_type']);
            $parameter['activity_type'] = $activityType;
        }
        $SpuDetail = Goods::Goods($goodsId, Goods::FIELDS_GROUP_DETAIL, $parameter, $uid, mGoodsBasicInfo::STATUS_APP_CAN_SEE_MAP);
        $version = version_compare($this->appVersion, '3.6.0', '>=');
        if ($version) {
            $SpuDetail = $this->isPlayVideo($SpuDetail);
        }
        //获取用户类型
        $user_info = dbUser::getUserInfoNew($uid);
        if($user_info && is_array($user_info)) {
            $user_type = (int)$user_info['type'];
        } else {
            $user_type = 0;
        }
        if($SpuDetail && is_array($SpuDetail)) {
            $SpuDetail['user_type'] = $user_type;
        }

        GoodsHistory::addBrowseHistory($uid, $goodsId);
        $this->setSuccess($SpuDetail);
    }

    private function isPlayVideo($spuDetail)
    {
        $spuDetail['is_play'] = 0;
        return $spuDetail;
    }
}
